#include <string.h>
#include <iostream>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <cstdio>

using namespace std;
//#define FUCK
typedef long long ll;
/*
1. 遍历会超时
2. 去重会超时
3. 统计之后，排序，找重复下标又超时
4. 这题太坑了，竟然卡语言。。。c语言能过
*/

//此方法超时
void method1(){
    ll n;
    while(cin >>n){
        string A,B;
        cin >> A;
        cin >> B;
        string tmp;
        for(ll i=0;i<n;i++){
            cin >> tmp;
            ll a=0,b=0;
            ll len=tmp.length();
            for(ll j=0;j<len;j++){
                if(A[j]==tmp[j])a++;
                if(B[j]==tmp[j]) b++;
            }
            cout <<max(a,b)<<endl;
        }
    }
}


void method2(){
    ll n;
    while(cin >>n){
        string A,B;
        cin >>A;
        cin >> B; 
        string tmp;

        while(n--){
            ll a=0,b=0;
            cin >>tmp;
            ll len=tmp.length();
            for(ll j=0;j<len;j++){
                a+=(!(A[j]^tmp[j]));
                // if(A[j]==tmp[j])a++;
                b+=(!(B[j]^tmp[j]));
                // if(B[j]==tmp[j]) b++;
            }            
            cout <<max(a,b)<<endl;
        }
    }
}

void method3(){
    int n;
    while(EOF!=scanf("%d",&n)){
        int N=1e6/n+100;
        char A[N]={0},B[N]={0},tmp[N]={0};

        if(EOF==scanf("%s",&A))return ;
        if(EOF==scanf("%s",&B))return;
        int len=strlen(A);
        while(n--){
            int a=0,b=0;
            memset(&tmp,0,sizeof(tmp));
            if(EOF==scanf("%s",&tmp))return;
            for(int i=0;i<len;i++){
                if(A[i]==tmp[i]) a++;
                if(B[i]==tmp[i]) b++;
            }
            printf("%d\n",max(a,b));
        }
       
    }

}



int main(){

#ifdef FUCK
    freopen("in1.txt","r",stdin);
    freopen("out1.txt","w",stdout);
    int start=clock();
#endif
    //method1();
    //method2();
    method3();


   
#ifdef FUCK
    int end=clock();
    
    double total_time = (double)(end - start) / CLOCKS_PER_SEC;
    cout <<"运行时间: " << total_time * 1000  <<" ms" <<endl;
#endif

    return 0;
}